﻿Public Class Clients

    ''' <summary>
    ''' Propriete retournant la liste des animaux du clients
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property listeAnimauxClient() As List(Of Animaux)
        Get
            listeAnimauxClient = New List(Of Animaux)

            Me.Animaux.Load()
            For Each animal In Me.Animaux
                If animal.Archive = False Then
                    listeAnimauxClient.Add(animal)
                End If
            Next

            Return listeAnimauxClient
        End Get
    End Property

    ''' <summary>
    ''' Propriete verifiant si le client à encore des factures impayés
    ''' retourne TRUE si le client a payé toute ses factures (ou n'en a pas)
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property isClientArchivable() As Boolean
        Get
            isClientArchivable = False
            'si la facture est payé l'etat de la facture est 2
            Me.Factures.Load()
            Dim requete As IEnumerable(Of Factures) = From uneFacture In Factures Select uneFacture Where uneFacture.Archive = False And uneFacture.Etat <> 2 And uneFacture.Clients.CodeClient = Me.CodeClient
            If requete.Count = 0 Then
                isClientArchivable = True
            End If
        End Get
    End Property

    ''' <summary>
    ''' Procedure d'archivage d'un client archive ses animaux et ses factures
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub archiverClient()

        'archivage de tous les animaux du client
        For Each animal In Me.Animaux
            If animal.Archive = False Then
                animal.archiverAnimal()
            End If
        Next
        'archivage de toutes les factures du client
        For Each facture In Me.Factures
            If facture.Archive = False Then
                facture.archiverFacture()
            End If
        Next
        'archivage du client
        Me.Archive = True


    End Sub

    ''' <summary>
    ''' procedure de modification d'un client
    ''' </summary>
    ''' <param name="nom"></param>
    ''' <param name="prenom"></param>
    ''' <param name="adresse1"></param>
    ''' <param name="adresse2"></param>
    ''' <param name="ville"></param>
    ''' <param name="codePostal"></param>
    ''' <param name="telephone"></param>
    ''' <param name="assurance"></param>
    ''' <param name="email"></param>
    ''' <remarks></remarks>
    Public Sub modifierClient(ByVal nom As String, ByVal prenom As String, ByVal adresse1 As String, ByVal adresse2 As String, ByVal ville As String, ByVal codePostal As String, ByVal telephone As String, ByVal assurance As String, ByVal email As String)

        Me.NomClient = nom
        Me.PrenomClient = prenom
        Me.Adresse1 = adresse1
        Me.Adresse2 = adresse2
        Me.Ville = ville
        Me.CodePostal = codePostal
        Me.NumTel = telephone
        Me.Assurance = assurance
        Me.Email = email

    End Sub

    Public Overrides Function ToString() As String
        Return Me.NomClient & " " & Me.PrenomClient
    End Function

End Class
